# def introduce(name,age):
#     print(f"我叫{name},今年{age}岁。")
# introduce(12,"张三")          #我叫12,今年张三岁。（位置参数）
# introduce(name="张三",age=12)       #关键字参数
#关键字参数和位置参数  混合使用时，位置参数必须要在关键字参数之前
# introduce("张三",age=12)
#introduce(age=12,'张三')       #SyntaxError: positional argument follows keyword argument
# def introduce(name,age=18):       #默认值参数
#     print(f"我叫{name},今年{age}岁。")
# # introduce('小明')
# introduce('小明','20')

# def introduce(age=18，name):       #默认值参数，排在非默认值参考前方会直接报错
# def sum_all(*numbers):               #任意多个位置参数 *args
#     print("收到的参数", numbers)
#     return sum(numbers)
# print(sum_all(1,2,3,4,5))
# def print_user_info(**info):           #任意多个关键字参数   **kwargs
#     print("用户信息")
#     for k, v in info.items():
#         print(f"{k}:{v}")
# print_user_info(name='wc',age=18,city='沈阳')

# def connect(host,*,port,timeout):            # 强制命名参数,在 * 或者 * args 之后的参数，必须使用关键字传入
#     print(f"链接{host}:{port},超时{timeout}秒。")
# connect("198.61.2.1",port=8080,timeout=5)

'''
    位置参数 - --默认参数 - -- * args - -- ** kwargs
'''


# def add(a,b):
#     return a + b         #返回值
# print(add(3,5))
#
# def tem():              #自动解包
#     return '张三',25,'工程师'
# name,age,job=tem()
# print(name,age,job)


#函数不能重名,覆盖了，容易引发，逻辑问题
# def f():
#     return'first'
# def f():
#     return'second'
# print(f())


#查看变量
# def demo():
#     age=29
#     score=90
#     print('局部变量',locals())
#     print("全局变量",list(globals().keys())[:4])
# demo()

# def  calc_sum(*nums):
#   return sum(nums)
# print(calc_sum(1,2,3,4))


# def print_info(**cord):
#     print(' ')
#     for k,v in cord.items():
#         print(f"{k}={v}")
# print_info(name='小红',age=16)

#
# def get_student():
#     return"李华", 17, "高二"
# name,age,grade = get_student()
# print(name,age,grade)
#
# x = "全局"
# def outer():
#     x = "外层"
#     def inner():
#         print(x)
#     inner()
# outer()
#
#
# count = 0
# def increment():
#     global count
#     count += 1  # 报错！请修正
# increment()
# print(count)
#
#
#
# def outer():
#     n = 10
#     def inner():
#         nonlocal n # 填空
#         n = 20
#     inner()
#     print(n)
# outer()


# def connect_db(host, *, port=3306, timeout=10):
#     print(f'连接{host},{port}，超时{timeout}秒')
# connect_db('localhost', port=5432, timeout=5)



# def demo():
#     a = 5
#     print("局部变量:", list(locals().keys()))
# demo()



# def safe_divide(a, b):

#1
# def  print_squares(n):
#     for i in range(1,n+1):
#         i=i**2
#         print(i)
# print_squares(3)
# 2
# def countdown(start):
#     while start >= 1:
#         print(start)
#         start -=1
# countdown(3)
#3
# def repeat_word(word, times=3):
#     for i in range(times):
#         print(word)
# repeat_word("Hi")
#4
# def sum_until_zero():
#     total = 0
#     while True:
#          num = int(input("输入数字（0 结束）："))
#          if num == 0:
#             break
#          total += num
#     return total
#
# result = sum_until_zero()
# print(f"总和是：{result}")

#5
# def find_max(*numbers):
#     max_i = numbers[0]
#     for i in numbers:
#         if i > max_i:
#          max_i = i
#     return max_i
# print(find_max(3, 7, 2, 9))
#6
# counter = 0
# def increment_loop():
#     global counter
#     while counter < 3:
#         counter += 1
#         print(counter)
#
# increment_loop()
# print("最终:", counter)
# '''
# 结果：
# #1
# #2
# #3
# #最终: 3
# '''
#7
# def  print_scores(**scores):
#     for sub,score in scores.items():
#         print(f'{sub}={score}')
# print_scores(语文=85,数学=92,英语=78)
#8
# def greet_until_stop(stop_word="quit"):
#     while True:
#         name =input("请输入名字（输入 quit 退出）：")
#         if name == stop_word:
#             print("（程序结束）")
#             break
#         print(f"Hello, {name}!")
#9
# students = [("张三", 18), ("李四", 19), ("王五", 17)]
# def print_all_students(students):
#     for name,age in students:
#         print(f'{name} {age}岁')
# print_all_students(students)
#10
# def count_even(nums):
#     count=0
#     for i in nums:
#         if i % 2 == 0:
#             count +=1
#     print(count)
# count_even([1, 2, 3, 4, 5, 6])

